<template>
  <div class="purchase-root">
    <el-card shadow="never" body-style="padding: 20px 20px 0px 20px;">
      <el-form
        ref="form"
        :rules="$rules.warehouseInRules"
        inline
        :model="form"
        class="form-options"
        label-width="100px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="唯一编码" prop="equipmentId">
              <el-input v-model="form.equipmentId" disabled/>
            </el-form-item>
            <el-form-item label="批次号" prop="batchNo">
              <el-input v-model="form.batchNo" disabled/>
            </el-form-item>
            <el-form-item label="入库时间" prop="inTime">
              <el-input v-model="form.inTime" disabled/>
            </el-form-item>
            <el-form-item label="产品种类" prop="fishSpecies">
              <el-input v-model="form.fishSpecies" disabled/>
            </el-form-item>
            <el-form-item label="鱼塘" prop="fishpondName">
              <el-input v-model="form.fishpondName" disabled/>
            </el-form-item>
            <el-form-item label="生产日期" prop="productionDate">
              <el-input v-model="form.productionDate" disabled/>
            </el-form-item>
            <el-form-item label="过期日期" prop="expirationDate">
              <el-input v-model="form.expirationDate" disabled/>
            </el-form-item>
            <el-form-item label="质检员" prop="qcName">
              <el-input v-model="form.qcName" disabled/>
            </el-form-item>
            <el-form-item label="数量" prop="inNum">
              <el-input v-model="form.inNum"/>
            </el-form-item>

            <el-form-item label="最近操作人" v-if="form.id">
              <el-input v-model="form.inName" disabled/>
            </el-form-item>

          </el-col>
        </el-row>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { addWarehouseIn } from '@/api/warehouse'
export default {
  name: 'WarehouseInComponent',
  props: {
    isOnlyRead: {
      type: Boolean,
      default: false
    },
    form: {
      type: Object,
      default: function() {
        return {
          id: '',
          busInDetailsId: '',
          equipmentId: '',
          batchNo: '',
          inTime: '',
          fishSpecies: '',
          fishpondName: '',
          productionDate: '',
          expirationDate: '',
          qcName: '',
          inNum: '',
          inName: ''
        }
      }
    }
  },
  data() {
    return {
      purchaserLoading: false,
      purchaserOptions: [],
      equipments: [{}, {}, {}, {}],
      equipmentTreeData: [],
      warehouseOptions: []
    }
  },
  mounted() {

  },
  methods: {
    // async validEquipmentData() {
    //   const equipmentP = []
    //   for (let i = 0; i < this.form.busInDetailsList.length; i++) {
    //     equipmentP.push(this.$refs['Equipment'][i].validData())
    //   }
    //   if (equipmentP.length > 0) {
    //     return Promise.all(equipmentP)
    //   } else {
    //     return new Promise(resolve => resolve())
    //   }
    // },
    saveAndSubmit() {

        this.$refs['form'].validate((valid) => {
          if (valid) {
            // 保存
            const param = { status: 1 }
            Object.assign(param, this.form)
            param.status = 1
            param.busInDetailsList.forEach(item => {
              const lastIndex = item.equipmentTypeId.length - 1
              item.equipmentTypeId = item.equipmentTypeId[lastIndex]
              item.inNum = item.num
            })
            addWarehouseIn(param).then(response => {
              this.$message({
                message: '保存提交成功',
                type: 'success'
              })
              this.$emit('onSubmit', {})
            })
          } else {
            return false
          }
        })

    },

    save() {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            const param = { status: 0}
            Object.assign(param, this.form)

            // 保存
            addWarehouseIn(param).then(response => {
              this.$message({
                message: '保存成功',
                type: 'success'
              })
              this.$emit('onSave', {})
            })
          } else {
            return false
          }
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.purchase-root {
  max-height: 680px;
  overflow-y: auto;

  ::v-deep .el-form-item__content {
    width: 185px !important;

    .el-date-editor.el-input, .el-date-editor.el-input__inner {
      width: 100%;
    }
  }

  ::v-deep .long-content {
    .el-form-item__content {
      width: 480px !important;

      .el-date-editor--datetimerange.el-input, .el-date-editor--datetimerange.el-input__inner {
        width: 100%;
      }

      .el-date-editor--daterange.el-input, .el-date-editor--daterange.el-input__inner, .el-date-editor--timerange.el-input, .el-date-editor--timerange.el-input__inner {
        width: 100%;
      }

      .el-cascader--small {
        width: 100%;
      }
    }
  }
}
</style>
